package com.lucyyun.lcrpceasy.server;

import io.vertx.core.Vertx;

/**
 * Description
 *
 * @author: lucyYun
 * @date: 2024/6/23 17:14
 */
public class VertxHttpServer implements HttpServer {
    @Override
    public void doStart(int port) {
        Vertx vertx = Vertx.vertx();
        io.vertx.core.http.HttpServer server = vertx.createHttpServer();
//        server.requestHandler(request -> {
//            //处理http请求
//            System.out.println("Received request:" + request.method() + " " + request.uri());
//            
//            request.response()
//                    .putHeader("content-type", "text/plain")
//                    .end("Hello from Vert.x HTTP server!");
//        });
        
        server.requestHandler(new HttpServerHandler());
        // 启动 HTTP 服务器并监听指定端口
        server.listen(port, result -> {
            if (result.succeeded()) {
                System.out.println("Server is now listening on port " + port);
            } else {
                System.err.println("Failed to start server: " + result.cause());
            }
        });
    }
}
